package initalize

import (
	"RoccBlog/config"
	"github.com/spf13/viper"
	"log"
	"os"
	"strings"
)

func InitConfig() *config.Config {

	conf := viper.New()
	dir, _ := os.Getwd()
	dir = strings.ReplaceAll(dir, "\\", "/")
	log.Println(dir)
	conf.SetConfigName("config")
	conf.SetConfigType("yaml")
	conf.AddConfigPath("./config/")

	if err := conf.ReadInConfig(); err != nil {
		log.Fatalln("读取文件失败", err.Error())
	}

	var confInstance config.Config
	conf.Unmarshal(&confInstance)
	return &confInstance
}
